package com.ruoyi.bysj.controller;

import java.time.format.DateTimeFormatter;
import java.util.List;

import com.ruoyi.bysj.domain.SysAppointment;
import com.ruoyi.bysj.service.ISysAppointmentService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bysj.domain.SysReception;
import com.ruoyi.bysj.service.ISysReceptionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 接待车主Controller
 * 
 * @author laow
 * @date 2021-10-25
 */
@RestController
@RequestMapping("/bysj/reception")
public class SysReceptionController extends BaseController
{
    @Autowired
    private ISysReceptionService sysReceptionService;
    @Autowired
    private ISysAppointmentService sysAppointmentService;

    /**
     * 查询接待车主列表
     */
    @PreAuthorize("@ss.hasPermi('bysj:reception:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAppointment sysAppointment)
    {
        startPage();
        List<SysAppointment> list = sysAppointmentService.selectSysAppointmentByDate();
        return getDataTable(list);
    }

    /**
     * 导出接待车主列表
     */
    @PreAuthorize("@ss.hasPermi('bysj:reception:export')")
    @Log(title = "接待车主", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysReception sysReception)
    {
        List<SysReception> list = sysReceptionService.selectSysReceptionList(sysReception);
        ExcelUtil<SysReception> util = new ExcelUtil<SysReception>(SysReception.class);
        return util.exportExcel(list, "接待车主数据");
    }

    /**
     * 获取接待车主详细信息
     */
    @PreAuthorize("@ss.hasPermi('bysj:reception:query')")
    @GetMapping(value = "/{receptionId}")
    public AjaxResult getInfo(@PathVariable("receptionId") Long receptionId)
    {
        return AjaxResult.success(sysReceptionService.selectSysReceptionByReceptionId(receptionId));
    }

    /**
     * 新增接待车主
     */
    @PreAuthorize("@ss.hasPermi('bysj:reception:add')")
    @Log(title = "接待车主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysReception sysReception)
    {
        sysReception.setReceptionName(getUsername());
        if (sysReception.getAppointmentId() !=null){
            return toAjax(sysReceptionService.insertSysReceptionByName(sysReception));
        }
        return toAjax(sysReceptionService.insertSysReception(sysReception));
    }


    /**
     * 修改接待车主
     */
    /*@PreAuthorize("@ss.hasPermi('bysj:reception:add')")
    @Log(title = "接待车主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult edit(@RequestBody SysReception sysReception)
    {
        sysReception.setReceptionName(getUsername());
        return toAjax(sysReceptionService.insertSysReceptionByName(sysReception));
    }*/

    /**
     * 删除接待车主
     */
    @PreAuthorize("@ss.hasPermi('bysj:reception:remove')")
    @Log(title = "接待车主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{receptionIds}")
    public AjaxResult remove(@PathVariable Long[] receptionIds)
    {
        return toAjax(sysReceptionService.deleteSysReceptionByReceptionIds(receptionIds));
    }
}
